package 蓝桥算法;

import 栈.LinkedListStack;
import 栈.Stack;

public class day12 {//栈实现队列
        Stack<Integer> stackIn = new LinkedListStack<>(10);
        Stack<Integer> stackOut = new LinkedListStack<>(10);

        public void push(int x) {
            stackIn.push(x);
        }

        public int pop() {
            dumpstackIn();//清空进栈
            return stackOut.pop();
        }

        public int peek() {
            dumpstackIn();
            return stackOut.peek();
        }

        public boolean empty() {
            return stackOut.isEmpty() && stackIn.isEmpty();
        }

        private void dumpstackIn() {//把进展的东西调入栈内
            if (!stackOut.isEmpty()) return;//确保第一批进的第一批出
            while (!stackIn.isEmpty()) {
                stackOut.push(stackIn.pop());
            }
        }
    public static void main(String[] args) {
       day12 a=new day12();
            a.push(1);
            a.push(2);
            a.push(3);
            for (int i = 0; i < 3; i++) {
                System.out.println(a.pop());
            }
    }

}
